package com.shoulder.boot.process.utils;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shoulder.boot.process.dto.FormQueryDTO;
import com.shoulder.boot.process.entity.Form;
import com.shoulder.boot.process.vo.FormVo;
import com.shoulder.mybatis.utils.PageUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.util.ObjectUtils;

public class FormUtils implements PageUtils<Form, FormVo> {

    public static FormUtils buildUtils() {
        return new FormUtils();
    }

    @Override
    public FormVo toVo(Form entity) {
        FormVo vo = new FormVo();
        BeanUtils.copyProperties(entity, vo);
        return vo;
    }
    public static LambdaQueryWrapper<Form> buildQueryWrapper(FormQueryDTO queryDTO) {
        LambdaQueryWrapper<Form> queryWrapper = new LambdaQueryWrapper<Form>().orderByDesc(Form::getCreateTime);
        queryWrapper.like(!ObjectUtils.isEmpty(queryDTO.getName()), Form::getName, queryDTO.getName());
        queryWrapper.like(!ObjectUtils.isEmpty(queryDTO.getMeta()), Form::getMeta, queryDTO.getMeta());
        return queryWrapper;
    }
}
